package pl.ydp.utils
{
	import flexunit.framework.TestCase;

	public class TestVersion extends TestCase
	{
		public function TestVersion(methodName:String=null) {
			super(methodName);
		}
		
		public function testParse():void {
			var v:Version = new Version();
			assertEquals( "Zero version major", 0, v.major );
			assertEquals( "Zero version minor", 0, v.minor );
			assertEquals( "Zero version micro", 0, v.micro );
			assertEquals( "Zero version build", "", v.build );
			
			v = new Version( "1" );
			assertEquals( "1 version major", 1, v.major );
			assertEquals( "1 version minor", 0, v.minor );
			assertEquals( "1 version micro", 0, v.micro );
			assertEquals( "1 version build", "", v.build );
			
			v = new Version( "1.2" );
			assertEquals( "1.2 version major", 1, v.major );
			assertEquals( "1.2 version minor", 2, v.minor );
			assertEquals( "1.2 version micro", 0, v.micro );
			assertEquals( "1.2 version build", "", v.build );
			
			v = new Version( "2.10.7" );
			assertEquals( "2.10.7 version major", 2, v.major );
			assertEquals( "2.10.7 version minor", 10, v.minor );
			assertEquals( "2.10.7 version micro", 7, v.micro );
			assertEquals( "2.10.7 version build", "", v.build );
			
			v = new Version( "1.2.3-15" );
			assertEquals( "1.2.3-15 version major", 1, v.major );
			assertEquals( "1.2.3-15 version minor", 2, v.minor );
			assertEquals( "1.2.3-15 version micro", 3, v.micro );
			assertEquals( "1.2.3-15 version build", "15", v.build );
			
			v = new Version( "3.2.1.integration" );
			assertEquals( "3.2.1.integration version major", 3, v.major );
			assertEquals( "3.2.1.integration version minor", 2, v.minor );
			assertEquals( "3.2.1.integration version micro", 1, v.micro );
			assertEquals( "3.2.1.integration version build", "integration", v.build );
		}
		
		public function testCompare():void {
			var v1:Version = new Version("1.2.3-integral");
			var v2:Version = new Version("1");
			
			assertTrue( v1+">"+v2, v1.compare(v2)>0 );
			assertTrue( v2+"<"+v1, v2.compare(v1)<0 );
			
			v2 = new Version("1.2");
			assertTrue( v1+">"+v2, v1.compare(v2)>0 );
			assertTrue( v2+"<"+v1, v2.compare(v1)<0 );
			
			v2 = new Version("1.2.3");
			assertTrue( v1+">"+v2, v1.compare(v2)>0 );
			assertTrue( v2+"<"+v1, v2.compare(v1)<0 );
			
			v2 = new Version("1.2.3.integral");
			assertTrue( v1+"=="+v2, v1.compare(v2)==0 );
			
			v1 = new Version( "1.0-beta/300" );
			v2 = new Version( "1.0-beta/300" );
			assertTrue( v1+"=="+v2, v1.compare(v2)==0 );
		}
		
		public function testToString():void {
			var v1:Version = new Version("1.2.3-integral");
			assertEquals( "1.2.3-integral", String(v1) );
			
			v1 = new Version("1.2");
			assertEquals( "1.2", String(v1) );
			
			v1 = new Version("1.0.2");
			assertEquals( "1.0.2", String(v1) );
			
			v1 = new Version("1.0.2.b");
			assertEquals( "1.0.2-b", String(v1) );
			
			v1 = new Version( "1.0-beta/300" );
			assertEquals( "1-beta/300", String(v1) );
		}
		
	}
}